# 检查和重启服务脚本

Write-Host "=== 视频会议服务检查和重启 ===" -ForegroundColor Cyan
Write-Host ""

# 1. 检查配置文件
Write-Host "1. 检查配置文件" -ForegroundColor Yellow
Write-Host "前端配置 (packages/web/.env):" -ForegroundColor Green
Get-Content packages\web\.env
Write-Host ""

Write-Host "后端配置 (packages/server/.env):" -ForegroundColor Green
Get-Content packages\server\.env | Select-String "MEDIASOUP_ANNOUNCED_IP", "CORS_ORIGIN", "PORT"
Write-Host ""

# 2. 检查 Vite 配置
Write-Host "2. 检查 Vite 配置 (packages/web/vite.config.ts):" -ForegroundColor Yellow
Get-Content packages\web\vite.config.ts | Select-String "host:", "port:"
Write-Host ""

# 3. 检查端口占用
Write-Host "3. 检查端口占用情况" -ForegroundColor Yellow
$port3100 = Get-NetTCPConnection -LocalPort 3100 -State Listen -ErrorAction SilentlyContinue
$port3101 = Get-NetTCPConnection -LocalPort 3101 -State Listen -ErrorAction SilentlyContinue

if ($port3100) {
    Write-Host "✅ 端口 3100 (前端) 正在监听" -ForegroundColor Green
    $port3100 | Select-Object LocalAddress, LocalPort, State | Format-Table
} else {
    Write-Host "❌ 端口 3100 (前端) 未监听" -ForegroundColor Red
}

if ($port3101) {
    Write-Host "✅ 端口 3101 (后端) 正在监听" -ForegroundColor Green
    $port3101 | Select-Object LocalAddress, LocalPort, State | Format-Table
} else {
    Write-Host "❌ 端口 3101 (后端) 未监听" -ForegroundColor Red
}

# 4. 检查防火墙规则
Write-Host "4. 检查防火墙规则" -ForegroundColor Yellow
$rules = Get-NetFirewallRule | Where-Object { $_.DisplayName -like "*视频会议*" } | Select-Object DisplayName, Enabled
if ($rules) {
    $rules | Format-Table
} else {
    Write-Host "⚠️ 未找到防火墙规则" -ForegroundColor Yellow
}

Write-Host ""
Write-Host "=== 配置检查完成 ===" -ForegroundColor Cyan
Write-Host ""
Write-Host "现在请手动操作：" -ForegroundColor Yellow
Write-Host "1. 在后端窗口按 Ctrl+C，然后运行: npm run dev:server" -ForegroundColor White
Write-Host "2. 在前端窗口按 Ctrl+C，然后运行: npm run dev:web" -ForegroundColor White
Write-Host "3. 前端启动后，应该看到类似输出：" -ForegroundColor White
Write-Host "   ➜  Local:   http://localhost:3100/" -ForegroundColor Gray
Write-Host "   ➜  Network: http://192.168.1.108:3100/" -ForegroundColor Gray
Write-Host ""

